package com.ruoyi.jihuo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jihuo.domain.JhTmTemplate;
import com.ruoyi.jihuo.service.IJhTmTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模板配置Controller
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/jihuo/template")
public class JhTmTemplateController extends BaseController
{
    @Autowired
    private IJhTmTemplateService jhTmTemplateService;

    /**
     * 查询模板配置列表
     */
    @PreAuthorize("@ss.hasPermi('jihuo:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(JhTmTemplate jhTmTemplate)
    {
        startPage();
        List<JhTmTemplate> list = jhTmTemplateService.selectJhTmTemplateList(jhTmTemplate);
        return getDataTable(list);
    }

    /**
     * 导出模板配置列表
     */
    @PreAuthorize("@ss.hasPermi('jihuo:template:export')")
    @Log(title = "模板配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JhTmTemplate jhTmTemplate)
    {
        List<JhTmTemplate> list = jhTmTemplateService.selectJhTmTemplateList(jhTmTemplate);
        ExcelUtil<JhTmTemplate> util = new ExcelUtil<JhTmTemplate>(JhTmTemplate.class);
        util.exportExcel(response, list, "模板配置数据");
    }

    /**
     * 获取模板配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('jihuo:template:query')")
    @GetMapping(value = "/{jhId}")
    public AjaxResult getInfo(@PathVariable("jhId") Long jhId)
    {
        return success(jhTmTemplateService.selectJhTmTemplateByJhId(jhId));
    }

    /**
     * 新增模板配置
     */
    @PreAuthorize("@ss.hasPermi('jihuo:template:add')")
    @Log(title = "模板配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JhTmTemplate jhTmTemplate)
    {
        return toAjax(jhTmTemplateService.insertJhTmTemplate(jhTmTemplate));
    }

    /**
     * 修改模板配置
     */
    @PreAuthorize("@ss.hasPermi('jihuo:template:edit')")
    @Log(title = "模板配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JhTmTemplate jhTmTemplate)
    {
        return toAjax(jhTmTemplateService.updateJhTmTemplate(jhTmTemplate));
    }

    /**
     * 删除模板配置
     */
    @PreAuthorize("@ss.hasPermi('jihuo:template:remove')")
    @Log(title = "模板配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jhIds}")
    public AjaxResult remove(@PathVariable String[] jhIds)
    {
        return toAjax(jhTmTemplateService.deleteJhTmTemplateByJhIds(jhIds));
    }
    /**
     * 获取店铺所有运费模版
     * @return
     */
    @GetMapping(value = "getShopFreightTemplate")
    public AjaxResult getShopFreightTemplate()
    {
        return success(jhTmTemplateService.getRedisShopFreightTemplate());
    }
}
